<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<%@ include file="../../../web/header.jsp" %>

<title>教师信息维护</title>
</head>

<body>
<div class="layui-collapse">
	<div class="layui-colla-item">
		<h2 class="layui-colla-title">教师信息</h2>
	
	<div class="layui-colla-content layui-show">
		<fieldset class="layui-elem-field layui-field-title"  >
	<legend>教师信息</legend>
      <form class="layui-form">
      	<div class="layui-form-item">
      	 	<label class="layui-form-label">教师工号</label>
      	    <div class="layui-input-inline">
      	    	<input type="text" class="layui-input" name="teacherId" placeholder="请输入工号"></input>
      	    
      	    </div>
      	    <label class="layui-form-label">姓名</label>
      	    <div class="layui-input-inline">
      	    	<input type="text" class="layui-input" name="teacherName" placeholder="请输入姓名"></input>
      	    
      	    </div>
      	  <label class="layui-form-label"></label>
      	    
      	   <span>
      	    	<input  type="button" class="layui-btn" lay-submit lay-filter="select"  name="action" value="查询" style="width:80px" id="select"></input> 	   
      	    	<button type="reset" class="layui-btn" value="重置" style="width:80px">重置</button>
      	    	<input type="javascript:;"  type="btn" class="layui-btn" onclick="add()" value="添加" style="width:80px" ></input>
      	    
      	    </span>
    	         	
      	</div>	
      	
      	<div >
<!--       	   <input type="hidden" name="action" value="page"/> -->
      	   <input type="hidden" name="pageIndex" value="1"/>
      	   <input type="hidden" name="pageLimit" value="10"/>
      	
      	</div>
      </from>
      	
	</fieldset>
	</div>
	</div>
	
</div>

<div class="layui-form" >
	<table class="layui-table">
		<colgroup>
		   <col width="%10"><col width="15%"><col width="15%">
		   <col width="%10"><col width="15%"><col width="15%">
		</colgroup>
		<thead>
			<tr>
			 	<th>序号</th><th>工号</th><th>姓名</th>
			 	<th>性别</th><th>职称</th><th>授课编号</th><th>电话</th>
			 	<th>操作</th>
			 	
			</tr>
		</thead>
		<tbody id="teacher_tbody">
		
		</tbody>
	</table>
	<div id="pageInfoUser" style="text-align:right;padding-right:30px"></div>

</div>

</body>

<script src="../../static/js/base.js"></script>
<script type="text/javascript">
element.render();
refresh();

formSubmit("/StudentMangers/TeacherServlet","submit(select)","json",function select(data){
	 
	 
     var datas = JSON.stringify(data);
     datas = eval("("+datas+")");
    
	var curr = $("input[name='pageIndex']").val();
	var limit = $("input[name='pageLimit']").val();
	
	

	
	setPageInfo("pageInfoUser",datas.count,curr,limit,function(obj,first){  //first 判断是否为首次
		
		var curr = $("input[name='pageIndex']").val(obj.curr);
		var limit = $("input[name='pageLimit']").val(obj.limit);
		
		//首次不执行
	    if(!first){
	      refresh();
	    }
	});  //分页
	
	
	
	var html="";
	
	$.each(datas.list,function(i,dom){
		i++;
		var id = dom.teacherId;
		var name = dom.teacherName?dom.teacherName:"";
		var title= dom.title?dom.title:"";
		var teacherSex = dom.teacherSex?dom.teacherSex:"";
		var courseId = dom.courseId?dom.courseId:"";
		var tel = dom.tel?dom.tel:"";
		var d={i:i,id:id,name:name,title:title,teacherSex:teacherSex,tel:tel,courseId:courseId};
	    var  laytpl = layui.laytpl;
		
		 html +=  laytpl($("#tradd").html()).render(d);
		
		
		  
	})
	$("#teacher_tbody").html(html);

	
})

refresh();

function refresh(){
	$("#select").click();
}

function dele(i,id){
	
	if(confirm("确定要删除吗？")){
					
		
		ajax("/StudentMangers/TeacherServlet",{action:"删除",teacherId:id},"text",function(data){
			
			
			if(data=="1"){			
			
				$("#tr"+i).remove();
				
				
				layer.msg("删除成功");
					refresh();
			}
			
		})
				
	}

}


function add(){
	
	
	layer.open({
		type:2,
		area:['750px','500px'],
		fixed:false,
		maxmin:true,
		content: "./add.jsp",
        end:refresh,
	})
	

}

function update(i,id,name,teacherSex,title,courseId,tel){
	
	layer.open({
		type:2,
		area:['800px','500px'],
		fixed:false,
		maxmin:true,
		content: "./update.jsp?i="+i+"&id="+id+"&name="+name+"&teacherSex="+teacherSex+"&title="+title+"&courseId="+courseId+"&tel="+tel,
        end:refresh,
	})
	
}



</script>

<script type="text/html" id="tradd">
<tr id="tr"+{{d.i}}}>
  <td>{{d.i}}</td>
  <td>{{d.id}}</td>
  <td>{{d.name}}</td>
  <td>{{d.teacherSex}}</td>
  <td>{{d.title}}</td>
  <td>{{d.courseId}}</td>
  <td>{{d.tel}}</td>
   <td>
  <a href="javascript:;"class="layui-btn layui-btn-danger" lay-submit lay-filter="delete" name="action" onclick="dele({{d.i}},{{d.id}})" value="删除">
<i class= "layui-icon layui-icon-delete" ></i>
</a>&nbsp&nbsp
  <a href="javascript:;"  class="layui-btn"  lay-submit lay-filter="update" name="action" onclick="update({{d.i}},'{{d.id}}','{{d.name}}','{{d.teacherSex}}','{{d.title}}','{{d.courseId}}','{{d.tel}}')">修改</a>
  </td>
</tr>
</script>
</html>

